// $Id: bool.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/proxy/bool.hpp>

namespace xpcom {
namespace {

void do_out_impl(bool_t* b, bool_t t)
{
    BOOST_CHECK(*b == t);
    *b = *b ? false_ : true_;
}

void do_out(bool& b, bool_t t)
{
    do_out_impl(proxy::bool_out(b), t);
}

void do_inout_impl(bool_t* b, bool_t t)
{
    BOOST_CHECK(*b == t);
    *b = *b ? false_ : true_;
}

void do_inout(bool& b, bool_t t)
{
    do_inout_impl(proxy::bool_inout(b), t);
}

}
}

BOOST_AUTO_TEST_CASE(test_bool_in)
{
    using namespace xpcom;

    bool b = false;
    BOOST_CHECK(proxy::bool_in(b) == false_);

    b = true;
    BOOST_CHECK(proxy::bool_in(b) == true_);
}

BOOST_AUTO_TEST_CASE(test_bool_out)
{
    using namespace xpcom;

    bool b = false;
    do_out(b, false_);
    BOOST_CHECK(b);

    b = true;
    do_out(b, false_);
    BOOST_CHECK(b);
}

BOOST_AUTO_TEST_CASE(test_bool_inout)
{
    using namespace xpcom;

    bool b = false;
    do_inout(b, false_);
    BOOST_CHECK(b);

    b = true;
    do_inout(b, true_);
    BOOST_CHECK(!b);
}
